let ipts = document.querySelectorAll('input')
console.log(ipts);
let box = document.querySelector('.box')
let isusername = false
ipts[0].onblur = function () {
    let username = ipts[0].value
    let reg = /^[\u2E80-\u9FFF]+$/
    if (reg.test(username)) {
        box.innerHTML = '输入格式正确'
        // this.nextElementSibling.style.display = 'block'
        isusername = true
        // 验证通过之后开始验证是否用户名存在
        let url = ` http://jx.xuzhixiang.top/ap/api/checkname.php`
        axios.get(url, {
            params: {
                username
            }
        }).then((res) => {
            console.log(res.data);
            this.nextElementSibling.innerHTML = res.data.msg;
            if (res.data.code == 1) {
                isusername = true
            } 
                if(res.data.code==0){
                    confirm('用户名已注册，请更换用户名')
                    ipts[0].value=''
                    location.reload()
                
            }
        })

    } else {
        box.innerHTML = '输入格式错误'
    }
}
let isPhonenumber = false;
ipts[1].onblur = function () {
    let reg = /^(13[0-9]|14[0-9]|15[0-9]|18[0-9]|17[0-9])\d{8}$/
    if (reg.test(this.value)) {
        isPhonenumber = true
        this.nextElementSibling.innerHTML = '格式输入正确'
    } else {
        this.nextElementSibling.innerHTML = '格式输入错误'
    }
}
let quicly_reg = document.querySelector('.quicly_reg')
quicly_reg.onclick = function () {
    let username = ipts[0].value
    let password = ipts[1].value
    if (isusername && isPhonenumber) {
        // 如果二者的输入框输入格式正确的话，发起注册请求
        let url = `http://jx.xuzhixiang.top/ap/api/reg.php`
        axios.get(url, {
            params: {
                username,
                password
            }
        }).then((res) => {
            console.log(res);
            // localStorage.setItem('username', username)
            // localStorage.setItem('password', password)
if(res.data.code==1){
    confirm(res.data.msg + '，请问要进行登录吗？');
         location.href = 'logins.html'
}
            // confirm(res.data.msg + '，请问要进行登录吗？');
            // if (res.data.code == 0) {
            //     location.href = 'logins.html'
            //     confirm(res.data.msg + '，请问要进行登录吗？');
            // }if(res.data.code==1){
            //     location.href = 'logins.html'
            //     confirm(res.data.msg + '，请问要进行登录吗？'); 
            // }
        })
    }
}